﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ur;

namespace Pixels.Logic.GameplayEvents
{
    class AliensBrokeThrough : GameplayEvent
    {
        int numDead = 0;
        int numDestroyed = 0;

        public AliensBrokeThrough() {
            var roll = Ur.Random.QuickRnd.d100;
            if (roll < 15) numDead = 1;
            else if (roll < 30) numDestroyed = 1;
        }

        internal override void execute() {            
            if (numDestroyed > 0) {
                var ns = World.Colony.allStructures.Count;                
                var strct = World.Colony.allStructures.ToArray().GetRandom();
                strct.destroyed = true;
                
            } else if (numDead > 0) {
                World.Colony.allColonists.ToArray().GetRandom().die();
            }   
        }

        internal override string getLongDescription() {
            var str1 = "Our defenses faltered! Aliens managed to break through and wreak havoc " ;
            var str2 = "";
            if (numDead + numDestroyed == 0) str2 = " but fortunately no damage has been done!";
            else if (numDestroyed > 0) {
                var ns = World.Colony.allStructures.Count;
                if (ns == 0) return "";
                var strct = World.Colony.allStructures.ToArray().GetRandom();
                strct.destroyed = true;
                str2 = " and they overrran our " + strct.getName();
            } else if (numDead > 0) {
                str2 = " and they devoured a colonist! ";
                //World.Colony.allColonists.ToArray()
            }
            return str1 + str2;
        }
    }
}
